
Ext.define('desarrollo.ProyectoForm', {
    extend: 'Ext.form.Panel',
    alias: 'widget.writerform',
    requires: ['Ext.form.field.Text'],
    initComponent: function(){
        Ext.apply(this, {
            activeRecord: null,
            iconCls: 'icon-proyecto',
            frame: true,
            title: 'Proyectos',
            defaultType: 'textfield',
            bodyPadding: 20,
            fieldDefaults: {
                anchor: '100%',
            },
            items: [{
                fieldLabel: 'Id',
                name: 'id',
                type: 'int',
                hidden: true,
            },{
                fieldLabel: '<b>Nombre</b>',
                fieldStyle: 'background-color: transparent; border: none; background-image: none;',
                name: 'nombre',
            }, {
				xtype: 'textarea',
                fieldLabel: '<b>Descripcion</b>',
                fieldStyle: 'background-color: transparent; border: none; background-image: none;',
                name: 'descripcion',
            }],
            dockedItems: [{
                xtype: 'toolbar',
                items: [{
                    iconCls: 'icon-fase',
                    itemId: 'fase',
                    text: '<b>Fases</b>',
                    hidden: true,
                    scope: this,
                    //disabled: true, 
                    handler: this.onFases
                },{	//Vacio
				}]
            },{
				weight: 1,
                xtype: 'toolbar',
                dock: 'bottom',
                items: ['->',{
                    iconCls: 'icon-grafo',
                    itemId: 'grafo',
                    text: '<b>Grafo</b>',
                    hidden: true,
                    scope: this,
                    //disabled: true, 
                    handler: this.onGrafo
                }, {
                    iconCls: 'icon-reset',
                    text: '<b>Reset</b>',
                    scope: this,
                    handler: this.onReset
                }]
            }]
        });
        this.callParent();
    },

    setActiveRecord: function(record){
        this.activeRecord = record;
        if (record) {
            
            
			
			
			//if (!this.down('#fase').isDisabled()){
				this.down('#fase').show();			
			//}     
			this.down('#grafo').show();
            this.getForm().loadRecord(record);
        } else {
            
            this.down('#grafo').hide();
            this.down('#fase').hide();
            this.getForm().reset();
        }
    },

	onFases: function(){
			var form = this.getForm();
			this.fireEvent('ddFases', form.getValues(true));            
	},
	

	onGrafo: function(){
				var form = this.getForm();
				id = extraer(form.getValues(true), 'id=', '&'); nombre = extraer(form.getValues(true), '&nombre=', '&descripcion=');
				  
				var winImagen = Ext.create('widget.window', {
					x:400,
					y: 200,
					resizable   : false,
					//draggable   : false,
					iconCls: 'icon-grafo',
					title: 'GRAFO - ' + nombre,
					closable: true,
					bodyStyle: 'background-color: #fff;',
					layout: 'fit',
					items: [{
						border: false
					},img = Ext.create('Ext.Img',{
					  id: 'img2',
					   height :380,
					   width: 650,
					   name: 'imgx',
					   src: 'grafo_proyecto/' + id
					})]
				});
				winImagen.show();       
		},	

    onReset: function(){
        this.setActiveRecord(null);
        this.getForm().reset();
        this.fireEvent('refresh');
    },
    

    
});
